#include "com.hpp"

using namespace std;

int main()
{
	int fd = open(FILE_PATH,O_WRONLY);
	if(fd < 0){
		perror("open:");
		exit(FIFO_OPEN_ERR);
	}
	cout << "client open file done" << endl;  //写端同理，也要等读端打开否则阻塞

	while(true)
	{
		char* buffer = NULL;
		size_t len = 0;
		printf("请输入需要对server说的话:");
		int x = getline(&buffer,&len,stdin);
		buffer[x - 1] = '\0';
		int n = write(fd,buffer,x - 1);
		if(n == -1){
			perror("write:");
			exit(FIFO_WRITE_ERR);
		}
		cout << x << endl;
	}

	close(fd);
	return 0;
}